import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SettingProvider extends ChangeNotifier {
  bool isCloseWelcomeBocchi = false; // 是否关闭欢迎页面
  double padding = 5.0; // 边距
  double radius = 2.0; // 圆角

  SettingProvider() {
    initSettings();
  }

  initSettings() async {
    final prefs = await SharedPreferences.getInstance();
    padding = prefs.getDouble('padding') ?? padding;
    radius = prefs.getDouble('radius') ?? radius;
    isCloseWelcomeBocchi = prefs.getBool('isCloseWelcomeBocchi') ?? false;
    notifyListeners();
  }

  void updateSettings() async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setDouble('padding', padding);
    prefs.setDouble('radius', radius);
  }

  void toggleWelcomePage(bool value) async {
    isCloseWelcomeBocchi = value;
    final prefs = await SharedPreferences.getInstance();
    await prefs.setBool('isCloseWelcomeBocchi', value);
    notifyListeners();
  }

  void resetToDefaults() async {
    padding = 5.0;
    radius = 2.0;
    updateSettings();
    notifyListeners();
  }
}
